/** DoctorDao */
package server.service.doctor;

import java.util.ArrayList;
import java.util.List;

import server.Database;
import domain.doctor.Doctor;
import domain.user.User;

/**
Interacts with the DATABASE 
 * @author jessienewman
 * @version $Revision: 1.0 $
 */
public class DoctorDao {
/**
 * Field DATABASE.
 */
private Database database;

	/**
	 * Constructor for DoctorDao.
	 */
	public DoctorDao() {
		database = Database.DATABASE;
	}
	
	/**
	 * Method getDoctor.
	 * @param id Integer
	
	 * @return Doctor */
	public Doctor getDoctor(Integer id) {
		for (User u : Database.DATABASE.users) {
			if (u instanceof Doctor && u.getUserId() == id) {
				return (Doctor) u;
			}
		}
		return null;
	}

	/**
	 * Method modifyNameFirst.
	 * @param id Integer
	 * @param nameFirst String
	 */
	public void modifyNameFirst(Integer id, String nameFirst) {
		Doctor d = getDoctor(id);
		d.setNameFirst(nameFirst);
	}
	
	/**
	 * Method modifyNameMiddle.
	 * @param id Integer
	 * @param nameMiddle String
	 */
	public void modifyNameMiddle(Integer id, String nameMiddle) {
		Doctor d = getDoctor(id);
		d.setNameMiddle(nameMiddle);
	}
	
	/**
	 * Method modifyNameLast.
	 * @param id Integer
	 * @param nameLast String
	 */
	public void modifyNameLast(Integer id, String nameLast) {
		Doctor d = getDoctor(id);
		d.setNameLast(nameLast);
	}
	
	/**
	 * Method getAllDoctors.
	
	 * @return Doctor[] */
	public List<Doctor> getAllDoctors() {
		ArrayList<Doctor> doctors = new ArrayList<Doctor>();
		for (User u : database.users) {
			if (u instanceof Doctor) {
				doctors.add((Doctor) u);
			}
		}
		return doctors;
	}
	
	/**
	 * super's toString
	
	 * @return super's toString */
	public String toString() {
		return super.toString();
	}
}
